package com.resys.mappers;

import com.resys.entity.po.Reservationorder;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 *  数据库操作接口
 */
public interface ReservationorderMapper<T,P> extends BaseMapper<T,P> {

	/**
	 * 根据OrderId更新
	 */
 	 Integer updateByOrderId(@Param("bean") T t,@Param("orderId") Integer orderId);


	/**
	 * 根据OrderId删除
	 */
	 Integer deleteByOrderId(@Param("orderId") Integer orderId);


	/**
	 * 根据OrderId获取对象
	 */
	 T selectByOrderId(@Param("orderId") Integer orderId);


	 void add(T reservationorder);
    @Select("SELECT SUM(total_price)  FROM Reservationorder WHERE status IN (1,3) and created_at BETWEEN #{start} AND #{end}")
	BigDecimal getSales(LocalDateTime start, LocalDateTime end);
    @Select("SELECT COUNT(*) FROM Reservationorder WHERE status In (0,2) and created_at BETWEEN #{start} AND #{end}")
	Integer getCancell(LocalDateTime start, LocalDateTime end);
    @Select("SELECT COUNT(*) FROM Reservationorder WHERE created_at BETWEEN #{start} AND #{end}")
	Integer getAll(LocalDateTime start, LocalDateTime end);
    @Select("SELECT * FROM Reservationorder WHERE status in (0,1) and room_id = #{roomId} and ( #{startDate} >= end_time or #{endDate} <= start_time)")
    List<Reservationorder> dispatchOrder(Integer roomId,Date startDate, Date endDate);
	@Select("SELECT * FROM reservationorder WHERE status in (0,1,3) and room_id = #{roomId} AND ( (created_at >= #{start} AND created_at < #{end})" +
			"      OR (end_time > #{start} AND end_time <= #{end})" +
			"      OR (created_at <= #{start} AND end_time >= #{end})" +
			"      OR (created_at >= #{start} AND end_time <= #{end})" +
			"  )" +
			"ORDER BY start_time;")
	List<Reservationorder> selectLockStatus(Integer roomId, Date start,Date end);
}
